package com.ruoyi.iot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.iot.domain.IotDataWaterPressureInfo;
import com.ruoyi.iot.domain.IotSensorMsg;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface IotSensorMsgMapper extends BaseMapper<IotSensorMsg> {

    @Insert({
            "<script>",
            "INSERT INTO iot_sensor_msg (remote_id, func_code, msg, send_time, report_time,type) VALUES",
            "<foreach collection='list' item='item' separator=','>",
            "(#{item.remoteId}, #{item.funcCode}, #{item.msg}, #{item.sendTime}, #{item.reportTime}, #{item.type})",
            "</foreach>",
            "</script>"
    })
    void batchInsert(List<IotSensorMsg> list);

    @Select({
            "SELECT * FROM iot_sensor_msg",
            "WHERE remote_id = #{remoteId}",
            "AND report_time = #{reportTime}"
    })
    List<IotSensorMsg> selectOneByRemoteIdAndReportTime( @Param("remoteId") String remoteId,
                                                         @Param("reportTime") String reportTime);

    @Select({
            "SELECT * FROM iot_sensor_msg",
            "WHERE type = #{type} AND state = 0 ",
            "ORDER BY report_time DESC"
    })
    List<IotSensorMsg> selectSensorMsgByType(@Param("type") String type);

    @Update({
            "<script>",
            "UPDATE iot_sensor_msg ",
            "SET state = 1 ",
            "WHERE id IN ",
            "<foreach collection='list' item='item' open='(' separator=',' close=')'>",
            "    #{item.id}",
            "</foreach>",
            "</script>"
    })
    int batchUpdateState(@Param("list")List<IotSensorMsg> msgList);

    @Select("SELECT * FROM iot_data_pressure_info")
    List<IotDataWaterPressureInfo> getAllPressureInfo();
}
